PRG        = master
OBJ        = main.o uart.o parani.o
MCU_TARGET = atmega16
OPTIMIZE   = -Os
DEFS       =
LIBS       =

CROSS   = avr-
CC      = $(CROSS)gcc
OBJCOPY = $(CROSS)objcopy
OBJDUMP = $(CROSS)objdump
CFLAGS  = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
LDFLAGS = -Wl,-Map,$(PRG).map


test: $(PRG).hex
	avrdude -p $(MCU_TARGET) -P /dev/ttyS0 -c ponyser -U flash:w:$(PRG).hex

all: $(PRG).hex

$(PRG).elf: $(OBJ)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

%.hex: %.elf
	$(OBJCOPY) -j .text -j .data -O ihex $< $@

%.lst: %.elf
	$(OBJDUMP) -h -S $< > $@

clean:
	rm -f *.o *~
	rm -f $(PRG).elf $(PRG).hex $(PRG).lst $(PRG).map
